package com.cykj.consumer;

import com.cykj.mapper.OrderMapper;
import com.cykj.pojo2.CyOrder;
import com.cykj.service.OrderService;
import com.cykj.vo.OrderVo;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(topic = "create-order",consumerGroup = "${rocketmq.consumer.create-group}")
public class CreateOrderConsumer implements RocketMQListener<OrderVo> {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public void onMessage(OrderVo vo) {
        CyOrder cyOrder = new CyOrder();
        cyOrder.setUserId(vo.getUserId());
        cyOrder.setGoodId(vo.getGoodId());
        cyOrder.setBuyCount(vo.getNum());
        cyOrder.setIsTimeOut(0);
        cyOrder.setPayState(0);
        int i =orderMapper.addOrder(cyOrder);
        System.out.println(cyOrder);
        GenericMessage<CyOrder> cyOrderGenericMessage = new GenericMessage<CyOrder>(cyOrder);

        rocketMQTemplate.asyncSend("cancel-order",cyOrderGenericMessage,null,10000,3);
    }

}
